using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BLL;
using BLL.Impl;
using System.Collections.Generic;

namespace WebUI.CargoCars
{
    public partial class CargoCars_List :BasicPage
    {
        private ICargoCarsManager cargoCarsManager;

        private List<Model.CargoCars> cargoCarsList;
        protected void Page_Load(object sender, EventArgs e)
        {
            cargoCarsManager = BLLFactory.CreateCargoCarsManager();
            cargoCarsList = cargoCarsManager.ListCargoCars();
            if (!IsPostBack)
            {
                Display();
            }
        }

        private void Display()
        {
            this.grvCargoCarsList.DataSource = cargoCarsList;
            this.grvCargoCarsList.DataKeyNames = new string[] { "CargoCarsSN" };
            this.grvCargoCarsList.DataBind();
        }

        protected void grvCargoCarsList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Model.CargoCars cargoCars = new Model.CargoCars();
            cargoCars.CargoCarsSN = Int32.Parse(this.grvCargoCarsList.DataKeys[e.RowIndex].Value.ToString());
            cargoCarsManager.DelectCargoCars(cargoCars);
            Display();
        }

        protected void grvCargoCarsList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.grvCargoCarsList.PageIndex = e.NewPageIndex;
            Display();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Model.CargoCars cargoCars = new Model.CargoCars();
            if (!String.IsNullOrEmpty(this.txtCargoCarsSn.Text.Trim()))
            {
                cargoCars.CargoCarsSN = Int32.Parse(this.txtCargoCarsSn.Text.Trim());
            }
            if (!String.IsNullOrEmpty(this.txtCargoCarsName.Text.Trim()))
            {
                cargoCars.CargoCarsName = this.txtCargoCarsName.Text.Trim();
            }
            if (!String.IsNullOrEmpty(this.txtTel.Text.Trim()))
            {
                cargoCars.Tel = this.txtTel.Text.Trim();
            }
            if (!String.IsNullOrEmpty(this.txtCargoCarsGrade.Text.Trim()))
            {
                cargoCars.CargoCarsGrade = Int32.Parse(this.txtCargoCarsGrade.Text.Trim());
            }
            cargoCarsList = cargoCarsManager.SelectCargoCars(cargoCars);
            Display();
        }
    }
}
